package com.game.init;

import com.alibaba.fastjson.JSON;
import com.dats.db.NameMap;
import com.dats.pool.InitPool;
import com.dats.util.Md5Util;
import com.game.hot.Manager;
import com.game.packet.Packet;

/**
 * @author sig
 * @since 2016/9/27
 */
public class InitMg implements com.dats.i.InitI, InitI {

    @Override
    public void calcMd5(Class<?> clazz, Object obj) {
        String tableName = NameMap.getTableName(clazz);
        String jsonStr = JSON.toJSONString(obj);
        String md5Str = Md5Util.md5(jsonStr);
        InitPool.md5Map.put(tableName, md5Str);
        InitPool.dicMap.put(tableName, obj);
    }

    @Override
    public void sendMd5(Packet req) {
        Packet res = new Packet(req);
        res.put("md5", InitPool.md5Map);
        Manager.getPackMg().sendPack(req, res);
    }

    @Override
    public void sendDic(Packet req) {
        Packet res = new Packet(req);
        res.put("dic", InitPool.dicMap);
        Manager.getPackMg().sendPack(req, res);
    }
}
